#!/usr/bin/python

import sys
import gc
gc.set_threshold(700, 1000, 10)

def main():
    d = {}
    for i, line in enumerate(sys.stdin):
        gene, locuses = line.split()
        d[int(gene)] = set(map(int, locuses.split(',')))
    
    gene_ids = sorted(d)
    
    for id1 in gene_ids:
        s1 = d[id1]
        for id2 in gene_ids:
            if id1 < id2:
                s2 = d[id2]
                ss = s1.intersection(s2)
                if ss:
                    print "%s,%s\t%s,%s,%s" % (id1, id2, len(s1), len(s2), len(ss))


if __name__ == '__main__':
    ##
    ## WARNING!
    ## Need >4Gb RAM
    ##
    main()
